#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <stdint.h>
#include <iostream>
#include <sys/time.h>

#include "TROOT.h" 
#include "TF1.h"
#include "TH1C.h"
#include "TH1I.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TH2D.h"
#include "TH3F.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TH3D.h"
#include "TApplication.h"
#include "TFile.h"
#include "TNetFile.h"
#include "TRandom.h"
#include "TTree.h"
#include "TBranch.h"
#include "TClonesArray.h"
#include "TStopwatch.h"
#include "TCanvas.h"
#include "TRandom3.h"
#include "TGraph.h"
#include "TMath.h"
#include "TArc.h"
#include "TVirtualFitter.h"
#include "TStyle.h"
#include "TLine.h"
#include "TEventList.h"
#include "TPaveText.h"
#include "TPaveLabel.h"
#include "TLegend.h"
void SetStyle();

void SetStyle()
{
//ild TStyle
TStyle* ildStyle = new  TStyle("ildStyle", "ILD Style");

//set the background color to white
ildStyle->SetFillColor(10);
ildStyle->SetFrameFillColor(10);
ildStyle->SetCanvasColor(10);
ildStyle->SetPadColor(10);
ildStyle->SetTitleFillColor(0);
ildStyle->SetStatColor(10);

//dont put a colored frame around the plots
ildStyle->SetFrameBorderMode(0);
ildStyle->SetCanvasBorderMode(0);
ildStyle->SetPadBorderMode(0);
ildStyle->SetLegendBorderSize(0);

//use the primary color palette
ildStyle->SetPalette(1,0);

//set the default line color for a histogram to be black
ildStyle->SetHistLineColor(kBlack);

//set the default line color for a fit function to be red
ildStyle->SetFuncColor(kRed);

//make the axis labels black
ildStyle->SetLabelColor(kBlack,"xyz");

//set the default title color to be black
ildStyle->SetTitleColor(kBlack);
 
//set the margins
ildStyle->SetPadBottomMargin(0.18);
ildStyle->SetPadTopMargin(0.10);
ildStyle->SetPadRightMargin(0.15);
ildStyle->SetPadLeftMargin(0.12);

//set axis label and title text sizes
ildStyle->SetLabelFont(42,"xyz");
ildStyle->SetLabelSize(0.04,"xyz");
ildStyle->SetLabelOffset(0.015,"xyz");
ildStyle->SetTitleFont(42,"xyz");
ildStyle->SetTitleSize(0.05,"xyz");
ildStyle->SetTitleSize(0.05f,"t");
ildStyle->SetTitleOffset(1.2,"yz");
ildStyle->SetTitleOffset(1.1,"x");
ildStyle->SetStatFont(42);
ildStyle->SetStatFontSize(0.07);
ildStyle->SetTitleBorderSize(0);
ildStyle->SetStatBorderSize(0);
ildStyle->SetTextFont(42);

//set line widths
ildStyle->SetFrameLineWidth(2);
ildStyle->SetFuncWidth(2);
ildStyle->SetHistLineWidth(2);

//set the number of divisions to show
ildStyle->SetNdivisions(506, "xy");

//turn off xy grids
ildStyle->SetPadGridX(0);
ildStyle->SetPadGridY(0);

//set the tick mark style
ildStyle->SetPadTickX(1);
ildStyle->SetPadTickY(1);

//turn off stats
ildStyle->SetOptStat(0);
ildStyle->SetOptFit(0);

//marker settings
ildStyle->SetMarkerStyle(20);
ildStyle->SetMarkerSize(0.7);
ildStyle->SetLineWidth(2); 

//done
ildStyle->cd();
//gROOT->ForceStyle();
//gStyle->ls();

}


#if 0 // old style
{
	TStyle *aStyle = new TStyle();
	//gStyle->SetOptStat(1111111);
	//gStyle->SetPadTickX(1);
	//gStyle->SetPadTickY(1);
	aStyle->SetOptStat("n");
	aStyle->SetOptStat(0);
	aStyle->SetPalette(1);
	aStyle->SetCanvasColor(0);
	aStyle->SetPadColor(0);
	aStyle->SetPadBorderMode(1);
	aStyle->SetFrameBorderMode(0);
	// use plain black on white colors

	// set the paper & margin sizes
	aStyle->SetPaperSize(20,26);
	aStyle->SetPadTopMargin(0.085);
	aStyle->SetPadRightMargin(0.15);
	aStyle->SetPadBottomMargin(0.15);
	aStyle->SetPadLeftMargin(0.15);

	// use large Times-Roman fonts
	aStyle->SetTextFont(132);
	aStyle->SetTextSize(0.08);
	aStyle->SetLabelFont(132,"x");
	aStyle->SetLabelFont(132,"y");
	aStyle->SetLabelFont(132,"z");
	aStyle->SetLabelSize(0.05,"x");
	aStyle->SetTitleSize(0.06,"x");
	aStyle->SetLabelSize(0.05,"y");
	aStyle->SetTitleSize(0.06,"y");
	aStyle->SetLabelSize(0.05,"z");
	aStyle->SetTitleSize(0.06,"z");

	// use bold lines and markers
	aStyle->SetMarkerStyle(20);
	aStyle->SetHistLineWidth(1.85);
	aStyle->SetLineStyleString(2,"[12 12]"); // postscript dashes

	// get rid of X error bars and y error bar caps
	//aStyle->SetErrorX(0.001);

	// put tick marks on top and RHS of plots
	//aStyle->SetPadTickX(1);
	//aStyle->SetPadTickY(1);
	aStyle->cd();
}
#endif
double GetMuMomemtum(double ke); // ke in keV
double GetMuMomemtum(double ke)
{
	double mass = 105.6; // MeV/c
	ke = ke/1000; // convert unit to MeV
	return sqrt(ke*ke + 2*mass*ke);
}
